﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using DBD.Common.Map;
using DBD.Common.NPOI;

namespace DBD.Common.Test
{
    class Program
    {
        static void Main(string[] args)
        {

            Dictionary<string, string> dic1 = new Dictionary<string, string>
            {
                {"Name", "名字"},
                {"Id", "序号"},
                {"Time", "时间"},
                {"Remark", "备注"},
                {"Sex", "性别"}
            };

            Dictionary<string, int> dic2 = new Dictionary<string, int>
            {
                {"Name", 0},
                {"Id", 3},
                {"Time",4},
                {"Remark",2},
                {"Sex",1}
            };


            DataTable table = ExcelHelper.ReadSheet(@"E:\Git\Common\DBD.Common\DBD.Common.Test\Test.xlsx", true);
            IEnumerable<Model> models1 = table.ToList<Model>(dic1);
            IEnumerable<Model> models2 = ExcelHelper.ReadSheet<Model>(@"E:\Git\Common\DBD.Common\DBD.Common.Test\Test.xlsx", dic1);
            IEnumerable<Model> models3 = ExcelHelper.ReadSheet<Model>(@"E:\Git\Common\DBD.Common\DBD.Common.Test\Test.xlsx", dic2, 1);

            foreach (Model model in models3)
            {
                model.Name = model.Name + "Test1";
            }

            ExcelHelper.WriteSheet(@"E:\Git\Common\DBD.Common\DBD.Common.Test\TestTmp.xlsx",
                @"E:\Git\Common\DBD.Common\DBD.Common.Test\Test1.xlsx", models3, dic2);

            MemoryStream stream = ExcelHelper.WriteSheet(@"E:\Git\Common\DBD.Common\DBD.Common.Test\TestTmp.xlsx", models3, dic2);

            FileStream writefile = new FileStream(@"E:\Git\Common\DBD.Common\DBD.Common.Test\Test2.xlsx", FileMode.Create, FileAccess.Write);
            writefile.Write(stream.ToArray(), 0, stream.ToArray().Length);
            writefile.Flush();
            writefile.Close();
            stream.Close();



            Console.WriteLine("回车结束");
            Console.Read();
        }
    }


    public class Model
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Sex { get; set; }
        public DateTime Time { get; set; }
        public decimal Remark { get; set; }
    }


    public enum Sex
    {
        Man = 1,
        WoMan = 2
    }

}
